package com.boot.order.config;

import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class CusterRestTemplateConfig {
    /**
     * 远程调用接口
     * @param builder
     * @return
     */
    @Bean
    // 负载均衡器,负载均衡的调用机制,加上该注解,才能远程调用注册中心的另一个stock-service应用名称模块,否则无法解析
    // 如果没有该注解,会把stock-service当成普通的网址www.xxx.com请求
    @LoadBalanced
    public RestTemplate restTemplate(RestTemplateBuilder builder){
        RestTemplate build = builder.build();
        return build;
    }
}
